<!--
title: 任务中心
description: 
published: true
date: 2025-07-02T15:58:38.738Z
tags: 
editor: ckeditor
dateCreated: 2025-06-19T07:10:12.467Z
-->

<h1>添加任务</h1>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 添加任务
job_info = sdk_add_job(pid, name, description, trigger, seconds=60, run_date=None, flow_id=None, code=None)</code></pre>
<p>&nbsp;</p>
<ul>
  <li>参数说明<br>pid：目录ID。值为：string<br>name：任务名。值为：string<br>description：任务描述。值为：string<br>trigger： &nbsp;任务类型。值为："date"或"interval"（date：指日期执行；interval：周期执行）<br>seconds：当trigger等于"interval"必填，要求大于0。值为：int<br>run_date：当trigger等于"date"必填，要求大于当前时间。值为：string<br>flow_id：关联的业务ID，<mark class="pen-red">如果code是空的话，必填。</mark>值为：string<br>code：任务要执行的代码，<mark class="pen-red">如果flow_id是空的话，必填。</mark>值为：string<br>&nbsp;</li>
</ul>
<h2>简单示例</h2>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 导入SDK
global sdk_add_job

##########################
# 周期任务
##########################

pid = "d1138d88-49ec-11f0-b168-c6ee2c8e08e7" # 目录ID
name = "SDK周期任务" # 任务名称
description = "SDK周期任务, description" # 任务描述
trigger = "interval" # 周期任务
seconds = 300 # 每1分钟执行一次
code = """log_print("周期任务", "INFO")""" # 任务执行代码

# 添加任务
job_info1 = sdk_add_job(pid, name, description, trigger, seconds=seconds, code=code)


##########################
# 定时任务
##########################
pid = "d1138d88-49ec-11f0-b168-c6ee2c8e08e7" # 目录ID
name = "SDK定时任务" # 任务名称
description = "SDK定时任务,description" # 任务描述
trigger = "date" # 定时任务
run_date = "2025-07-09 16:00:00" # 指定日期执行
code = """log_print("定时任务", "INFO")""" # 任务执行代码

# 添加任务
job_info2 = sdk_add_job(pid, name, description, trigger, run_date=run_date, code=code)

return None</code></pre>
<p>&nbsp;</p>
<h1>获取项任务信息</h1>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 获项任务信息
job_info = sdk_get_job(id)</code></pre>
<p>&nbsp;</p>
<ul>
  <li>参数说明<br>id：平台任务ID。值为&nbsp;string</li>
  <li>返回说明<br>job_info：值为<br>&nbsp;</li>
</ul>
<pre><code class="language-plaintext">{
    "code": null,
    "createTime": "2025-06-15 21:30:02",
    "createUser": "fa11e670-2413-11f0-aa51-0a4444b8d20c",
    "dataLevel": "normal",
    "description": "test",
    "flowId": "b4972d68-49ec-11f0-bbb5-c6ee2c8e08e7",
    "id": "d6f4a7fa-49ec-11f0-845f-c6ee2c8e08e7",
    "jobId": "d6ef550c-49ec-11f0-845f-c6ee2c8e08e7",
    "jobParameter": {
        "coalesce": true,
        "code": null,
        "id": "d6ef550c-49ec-11f0-845f-c6ee2c8e08e7",
        "project_id": "b90ba90e-2431-11f0-a3b3-f2cf1bfaab0e",
        "replace_existing": true,
        "run_date": null,
        "seconds": 1,
        "trigger": "interval"
    },
    "name": "test",
    "next_run_time": null,
    "pid": "d1138d88-49ec-11f0-b168-c6ee2c8e08e7",
    "projectId": "b90ba90e-2431-11f0-a3b3-f2cf1bfaab0e",
    "updateTime": "2025-06-15 21:30:02",
    "updateUser": "fa11e670-2413-11f0-aa51-0a4444b8d20c"
}</code></pre>
<p>&nbsp;</p>
<h2><strong>简单示例</strong></h2>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 以接口代码为例

# 导入SDK
global sdk_get_job

# 平台文件ID
id = "d6f4a7fa-49ec-11f0-845f-c6ee2c8e08e7"
job_info = sdk_get_job(id)

return job_info</code></pre>
<p>&nbsp;</p>
<h1>获取项目任务列表</h1>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 获取项目任务列表
project_jobs = sdk_get_jobs()</code></pre>
<p>&nbsp;</p>
<ul>
  <li>返回说明<br>project_jobs：值为<br>&nbsp;</li>
</ul>
<pre><code class="language-plaintext">[
    {
        "code": null,
        "createTime": "2025-06-15 21:30:02",
        "createUser": "fa11e670-2413-11f0-aa51-0a4444b8d20c",
        "dataLevel": "normal",
        "description": "test",
        "flowId": "b4972d68-49ec-11f0-bbb5-c6ee2c8e08e7",
        "id": "d6f4a7fa-49ec-11f0-845f-c6ee2c8e08e7",
        "jobId": "d6ef550c-49ec-11f0-845f-c6ee2c8e08e7",
        "jobParameter": {
            "coalesce": true,
            "code": null,
            "id": "d6ef550c-49ec-11f0-845f-c6ee2c8e08e7",
            "project_id": "b90ba90e-2431-11f0-a3b3-f2cf1bfaab0e",
            "replace_existing": true,
            "run_date": null,
            "seconds": 1,
            "trigger": "interval"
        },
        "name": "test",
        "next_run_time": null,
        "pid": "d1138d88-49ec-11f0-b168-c6ee2c8e08e7",
        "projectId": "b90ba90e-2431-11f0-a3b3-f2cf1bfaab0e",
        "updateTime": "2025-06-15 21:30:02",
        "updateUser": "fa11e670-2413-11f0-aa51-0a4444b8d20c"
    },
    ...
]</code></pre>
<p>&nbsp;</p>
<h2><strong>简单示例</strong></h2>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 以接口代码为例

# 导入SDK
global sdk_get_jobs

# 获取项目列表
project_jobs = sdk_get_jobs()

return project_jobs</code></pre>
<p>&nbsp;</p>
<h1>开启任务</h1>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 开启任务
sdk_start_job(job_id)</code></pre>
<p>&nbsp;</p>
<ul>
  <li>参数说明<br>job_id：平台任务ID。值为&nbsp;string</li>
</ul>
<h2><strong>简单示例</strong></h2>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 以接口代码为例

# 导入SDK
global sdk_start_job

# 任务ID
job_id = "d6ef550c-49ec-11f0-845f-c6ee2c8e08e7"
sdk_start_job(job_id)

return "开启成功"</code></pre>
<p>&nbsp;</p>
<h1>停止任务</h1>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 停止任务
sdk_stop_job(job_id)</code></pre>
<p>&nbsp;</p>
<ul>
  <li>参数说明<br>job_id：平台任务ID。值为&nbsp;string<br>&nbsp;</li>
</ul>
<h2><strong>简单示例</strong></h2>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 以接口代码为例

# 导入SDK
global sdk_stop_job

# 任务ID
job_id = "d6ef550c-49ec-11f0-845f-c6ee2c8e08e7"
sdk_stop_job(job_id)

return "停止成功"</code></pre>
<p>&nbsp;</p>
<h1>立即执行任务</h1>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 立即执行任务
sdk_exec_job(job_id)</code></pre>
<p>&nbsp;</p>
<ul>
  <li>参数说明<br>job_id：平台任务ID。值为&nbsp;string<br>&nbsp;</li>
</ul>
<h2><strong>简单示例</strong></h2>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 以接口代码为例

# 导入SDK
global sdk_exec_job

# 任务ID
job_id = "d6ef550c-49ec-11f0-845f-c6ee2c8e08e7"
sdk_exec_job(job_id)

return "立即执行任务成功"</code></pre>
<p>&nbsp;</p>
<h1>更新任务</h1>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 更新任务
job_info = sdk_update_job(id, name, description, trigger, seconds=60, run_date=None, flow_id=None, code=None)</code></pre>
<p>&nbsp;</p>
<ul>
  <li>参数说明<br>参数说明<br>id：任务ID。值为：string<br>name：任务名。值为：string<br>description：任务描述。值为：string<br>trigger： &nbsp;任务类型。值为："date"或"interval"（date：指日期执行；interval：周期执行）<br>seconds：当trigger等于"interval"必填，要求大于0。值为：int<br>run_date：当trigger等于"date"必填，要求大于当前时间。值为：string<br>flow_id：关联的业务ID，<mark class="pen-red">如果code是空的话，必填。</mark>值为：string<br>code：任务要执行的代码，<mark class="pen-red">如果flow_id是空的话，必填。</mark>值为：string</li>
</ul>
<p>&nbsp;</p>
<h2><strong>简单示例</strong></h2>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 以接口代码为例

# 导入SDK
global sdk_update_job

##########################
# 周期任务
##########################

id = "5f4416e8-4a08-11f0-a3cd-e23276cb5279" # 目录ID
name = "新SDK周期任务" # 任务名称
description = "新SDK周期任务, description" # 任务描述
trigger = "interval" # 周期任务
seconds = 400 # 每1分钟执行一次
code = """print_log("周期任务", "INFO")""" # 任务执行代码

# 添加任务
job_info1 = sdk_update_job(id, name, description, trigger, seconds=seconds, code=code)


##########################
# 定时任务
##########################
id = "5f619a9c-4a08-11f0-a3cd-e23276cb5279" # 目录ID
name = "新SDK定时任务" # 任务名称
description = "新SDK定时任务,description" # 任务描述
trigger = "date" # 定时任务
run_date = "2025-06-27T16:00:00.000Z" # 指定日期执行
code = """print_log("定时任务", "INFO")""" # 任务执行代码

# 添加任务
job_info2 = sdk_update_job(id, name, description, trigger, run_date=run_date, code=code)

return {"新周期任务": job_info1, "新定时任务": job_info2}</code></pre>
<p>&nbsp;</p>
<h1>删除任务</h1>
<p>&nbsp;</p>
<pre><code class="language-plaintext">#  删除任务
sdk_delete_job(job_id)</code></pre>
<p>&nbsp;</p>
<ul>
  <li>参数说明<br>job_id：平台任务ID。值为&nbsp;string<br>&nbsp;</li>
</ul>
<h2><strong>简单示例</strong></h2>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 以接口代码为例

# 导入SDK
global sdk_delete_job

# 任务ID
job_id = "d6ef550c-49ec-11f0-845f-c6ee2c8e08e7"
sdk_delete_job(job_id)

return "删除任务成功"</code></pre>
<p>&nbsp;</p>
